package file;

import java.io.*;

public class Pet {


    public static String chStr(String olStr, String name, String type, String master){
        olStr="\n"+olStr.replace("前","后");
        olStr=olStr.replace("前","后");
        olStr=olStr.replace("{name}",name);
        olStr=olStr.replace("{type}",type);
        olStr=olStr.replace("{master}",master);
        return olStr;
    }

    public static void main(String[] args) throws IOException {
        try{
            FileReader fr=new FileReader(new File("D:/java/pet.txt"));//写入文件
            BufferedReader bfr=new BufferedReader(fr);//使用Buff来
            String Str=bfr.readLine();
            Str=chStr(Str,"ouou","狗","wj");
            FileWriter fw=new FileWriter(new File("D:/java/pet.txt"),true);//文件的写出，true表示员文件上添加
            BufferedWriter bfw=new BufferedWriter(fw);//使用Buffere输入和输出
            fw.write(Str);
            fw.flush();

            //文件的替换
            File file =new File("D:/java/io/pet.txt");
            File file1=new File("D:/java/io/pet1.txt");
            if (file1.exists()){
                file.createNewFile();
            }else  if (!file1.exists()){
                file1.createNewFile();
            }
            System.out.println(file);
            System.out.println(file1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
